/*
 * @Descripttion:routerStore
 * @LastEditors: xzh
 * @LastEditTime: 2023-08-05 14:09:33
 */
import { object_Inf } from "@/utils/typings/index.type";
import { defineStore } from "pinia";
import { routerHistory_Inf, routerMeta_Inf, router_Inf } from "./index.type";

const useRouterStore = defineStore("routerStore", {
  state: (): router_Inf => ({
    routerMenuArr: [], //路由格式菜单
    routerHistoryArr: [], //路由历史记录
    sidmenuArr: [], //菜单原始数据
    routerMetaArr: [], //路由参数
    firstRouter: "", //一级菜单路由
  }),
  //开启持久化
  persist: {
    enabled: true,
  },
  actions: {
    /**
     * @Author: xzh
     * @Descripttion:设置路由缓存
     * @Param:
     * @param {object_Inf} param1
     */
    setRouteArr({ routerMenuArr, sidmenuArr }: object_Inf) {
      this.routerMenuArr = routerMenuArr;
      this.sidmenuArr = sidmenuArr;
    },
    /**
     * @Author: xzh
     * @Descripttion:设置路由历史缓存
     * @Param:
     * @param {Array} routerHistoryArr-路由历史记录
     */
    setRouterHistoryArr(
      routerHistoryArr: Array<routerHistory_Inf> | Array<object_Inf>
    ) {
      this.routerHistoryArr = routerHistoryArr;
    },
    /**
     * @Author: xzh
     * @Descripttion:设置路由参数缓存
     * @Param:
     * @param {Array} routerMetaArr-路由参数
     */
    setRouterMetaArr(routerMetaArr: Array<routerMeta_Inf>) {
      this.routerMetaArr = routerMetaArr;
    },
    /**
     * @Author: xzh
     * @Descripttion:设置一级菜单路由
     * @Param:
     */
    setFirstRouter(firstRouter: string) {
      this.firstRouter = firstRouter;
    },
  },
});

export default useRouterStore;
